nodeTree=[
{"id":1, "pId":None, "name":"node-1", "leaf": True },
{"id":2, "pId":None, "name":"node-2", "leaf": True },
{"id":3, "pId":1, "name":"node-3", "leaf": True },
{"id":4, "pId":3, "name":"node-4", "leaf": True },
{"id":5, "pId":4, "name":"node-5", "leaf": False },
{"id":6, "pId":3, "name":"node-6", "leaf": True },
{"id":7, "pId":6, "name":"node-7", "leaf": False },
{"id":8, "pId":3, "name":"node-8", "leaf": True },
{"id":9, "pId":8, "name":"node-9", "leaf": False },
{"id":10, "pId":3, "name":"node-10", "leaf": False },
{"id":11, "pId":2, "name":"node-11", "leaf": True },
{"id":12, "pId":11, "name":"node-12", "leaf": False },
{"id":13, "pId":11, "name":"node-13", "leaf": True },
{"id":14, "pId":13, "name":"node-14", "leaf": False }
]


def f(id,nodeTree,res):
    curres=[]
    for info in nodeTree:
        pid = info["pId"]
        if pid == id:
            curid = info["id"]
            curres.append(curid)

    res += curres
    for i in curres:
        res += f(i,nodeTree,res)
    return res

res = f(3,nodeTree,[])
P = []
for id in res:
    for infor in nodeTree:
        curid = infor["id"]
        if id == curid and infor["leaf"] == False:
            P.append(id)
res = []
P = list(set(P))
P.sort()
for i in P:
    res.append(nodeTree[i-1])
print(res)





